package Queue;
import LinkList.*;
public class LinkedListCircularQueue {
    public ListNode head;
    public ListNode tail;
    public int usedSize;
    public int capacity;
    public LinkedListCircularQueue(int k) {
        capacity=k;
    }

    public boolean enQueue(int value) {
        if(isFull()) {
            return false;
        }
        ListNode node=new ListNode(value);
        if(head==null) {
            head=tail=node;
        }else {
            tail.next=node;
            tail=node;
        }
        usedSize++;
        return true;
    }

    public boolean deQueue() {
        if(isEmpty()) {
            return false;
        }
        head=head.next;
        usedSize--;
        return true;
    }

    public int Front() {
        if(isEmpty()) {
            return -1;
        }
        return head.data;
    }

    public int Rear() {
        if(isEmpty()) {
            return -1;
        }
        return tail.data;
    }

    public boolean isEmpty() {
        return usedSize==0;
    }

    public boolean isFull() {
        return usedSize==capacity;
    }
}
